home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / logit.c.z / logit.c
C/C++ Source or Header  |  1996-05-06  |  4KB  |  135 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: logit.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the local
  29.  *    libpod log file write function.
  30.  *
  31.  *    Usage: logit [-j job_id] [-u username]
  32.  *                printer_name start|end|{msg_code}
  33.  *
  34.  *    The message parameter specified on the command-line determines
  35.  *    the standard message that will be written to the log file.
  36.  *
  37.  *    start - prints a standard print job start message in the log file
  38.  *    end - prints a standard print job end message in the log file
  39.  *    msg_code - any valid message code number. Code numbers can be
  40.  *            specified in decimal, hex or octal.
  41.  *
  42.  *    Note: you must have root or lp permission to successfully run this
  43.  *    program.
  44.  *
  45.  **************************************************************************/
  46.  
  47.  
  48. #ident "$Revision: 1.1 $"
  49.  
  50.  
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #include <getopt.h>
  55. #include <pod.h>
  56.  
  57.  
  58. #define HANDLE_ERROR(pname)    { \
  59.                 PDPerror(pname); \
  60.                 exit(1); \
  61.                 }
  62.  
  63. void usage(char*);
  64.  
  65.  
  66. int main(int argc, char **argv)
  67. {
  68.     int ch, msg_code;
  69.     char *job_id = NULL;
  70.     char *username = NULL;
  71.     char *msg_code_str, *printer_name;
  72.     PDMessageStruct msg;
  73.  
  74.     /*
  75.      * Get command line switches
  76.      */
  77.     while ((ch = getopt(argc, argv, "j:u:")) != -1) {
  78.     switch (ch) {
  79.         case 'j':
  80.         job_id = optarg;
  81.         break;
  82.         case 'u':
  83.         username = optarg;
  84.         break;
  85.         case '?':
  86.         default:
  87.         usage(argv[0]);
  88.         exit(1);
  89.     }
  90.     }
  91.  
  92.     /*
  93.      * Get printer name and message code from command-line
  94.      */
  95.     if (argc < optind + 2) {
  96.     usage(argv[0]);
  97.     exit(1);
  98.     }
  99.     printer_name = argv[optind];
  100.     msg_code_str = argv[optind+1];
  101.     if (!strcasecmp(msg_code_str, "start"))
  102.     msg_code = PD_INFO_JOB_START;
  103.     else if (!strcasecmp(msg_code_str, "end"))
  104.     msg_code = PD_INFO_JOB_END;
  105.     else {
  106.         if ((msg_code = strtol(msg_code_str, (char**)NULL, 0)) == 0) {
  107.         (void)fprintf(stderr, "Invalid message code: %s\n",
  108.                 msg_code_str);
  109.         exit(1);
  110.     }
  111.     }
  112.  
  113.     /*
  114.      * Construct a standard message based on the message code
  115.      */
  116.     if (PDMakeMessage(&msg, msg_code) < 0)
  117.     HANDLE_ERROR(argv[0]);
  118.  
  119.     /*
  120.      * Write the log entry
  121.      */
  122.     if (PDLocalWriteLog(printer_name, job_id, username, &msg) < 0)
  123.     HANDLE_ERROR(argv[0]);
  124.  
  125.     return 0;
  126. }
  127.  
  128.  
  129. void usage(char *progname)
  130. {
  131.     (void)fprintf(stderr, "Usage: %s [-j job_id] [-u username] ", progname);
  132.     (void)fprintf(stderr, "printer_name start | end | {msg_code}\n");
  133. }
  134.  
  135.